package com.sxran.im.handler;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sxran.im.bean.MessageReqBody;
import com.sxran.im.controller.ImController;
import com.sxran.im.dao.ImFriendMapper;
import com.sxran.im.info.ImFriend;
import com.sxran.im.info.ImGroup;
import com.sxran.im.info.ImUser;
import com.sxran.im.info.ImUserGroup;
import com.sxran.im.service.ChatService;
import com.sxran.im.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class GetFriendListCmdHandler extends AbstractCmdHandler<MessageReqBody>{
    @Resource
    private ImFriendMapper imFriendMapper;
    @Resource
    private UserService userService;
    @Override
    public Object doBeanService(MessageReqBody json) {
        // 查询当前用户拥有的用户列表。
        String userId = ImController.getCurUserId();
        LambdaQueryWrapper<ImFriend> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ImFriend::getUserId , userId);
        List<ImFriend> imFriends = imFriendMapper.selectList(queryWrapper);
        // 用户详情。
        List<ImUser> users = imFriends.stream().map(x -> userService.selectByUserId(x.getFriendUid()) ).collect(Collectors.toList());
        return users;
    }
}
